/**
 * Created by PanJiaChen on 16/11/18.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  const valid_map = ['admin', 'editor']
  return valid_map.indexOf(str.trim()) >= 0
}

export function validPhone(rule, value, callback) {
  if (value === '') {
    callback(new Error('请输入手机号码'))
  } else {
    if (!/^0?1[3|4|5|6|7|8][0-9]\d{8}$/.test(value)) {
      callback(new Error('请输入正确的手机号码'))
    }
    callback()
  }
}

